//
//  MBDGroupDescCellModel.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/20.
//

import Foundation

import YYText

class MBDGroupDescCellModel : MBDGroupDetailCommonCellModel {
    var groupDescTextLayout : YYTextLayout?
    static let MarginTop : CGFloat = 0
    static let MarginBottom : CGFloat = 0
    static let MarginDescLabelLeftAndRight : CGFloat = 7

    override var groupDetail: MBDGroupDetailModel! {
        didSet {
            let groupInfo = self.groupDetail.groupDesc!
            let groupDetailAttributeString = NSMutableAttributedString(string: groupInfo )
            groupDetailAttributeString.yy_font = UIFont.systemFont(ofSize: 15)
            groupDetailAttributeString.yy_lineSpacing = 4
            groupDetailAttributeString.setDynamicTextColor()
            
            let groupDetailContainer = YYTextContainer()
            
            let groupDetailWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDGroupDescCellModel.MarginLeftAndRightBackgroundView * 2 - MBDGroupDescCellModel.MarginDescLabelLeftAndRight * 2
            groupDetailContainer.size = CGSizeMake(groupDetailWidth , CGFLOAT_MAX)
            let groupDetailLayout = YYTextLayout(container: groupDetailContainer, text: groupDetailAttributeString)
            
            self.groupDescTextLayout = groupDetailLayout
        }
    }
    
    override func cellHeight() -> CGFloat {
        return MBDGroupDescCellModel.MarginTop + (self.groupDescTextLayout?.textBoundingSize.height ?? 0) + MBDGroupDescCellModel.MarginBottom
    }
}
